<include file="public@header">
<body style="background: #1f1e24">
   <h3 class="mytitle" style="margin-top: 0.8rem;">推荐好友</h3>
    <div class="sharebg headhead">
    <img src="__STATIC__/hybit/images/share3.png" style="width:100%" alt="">
<!--
    <div class="haibaobg" id="haibaobg">
        <img src="__STATIC__/hybit/images/haibao.jpg" alt="">
        <div id="qrcode" class="ewmimg"></div>
         <img src="__STATIC__/hybit/images/ewm.png" alt="" class="ewmimg"> 
    </div>
-->
    <div class="zz_divewm">
        <div id="qrcode" class="ewmimg"></div>
        <p>扫二维码注册</p>
    </div>
    
       
    <div class="haibaofoot">
        <div class="haibao_yqm">
            <p class="haibao_yqmp1">{:lang('Invitation code')}</p>
            <input type="text" value="{$user_relation.invitation_code}" readonly id="haibaoa">
            <p class="haibao_yqmp2" onclick="CopyCode()"><img src="__STATIC__/hybit/images/fuzhi1.png" alt="">{:lang('Copy')}</p>
        </div>
        <div class="haibaofootbtn">
            <button class="haibaofootbtn1" onclick="sctp()" >{:lang('Save')}</button>
            <button class="haibaofootbtn2" onclick="CopyUrl()">{:lang('Link')}</button>
        </div>
        <input type="text" style="position: absolute;opacity: 0;left:-10000px;" id="url" value="{:cmf_get_domain()}{:url('user/register/index',array('recommender_code'=>$user_relation.invitation_code))}" readonly>
    </div>
    </div>
    <div class="alertdiv" style="display: none;">
        <div class="zz_alert">
            <p>复制成功</p>
            <div class="zz_alertbtn">
                <p class="zz_alertbtnqr" onclick="closezalert(this)">确认</p>
                <p class="zz_alertbtnqx" onclick="closezalert(this)">取消</p>
            </div>
        </div>
    </div>
    <script src="__STATIC__/hybit/js/jquery.min.js"></script>
    <script src="__STATIC__/hybit/js/html2canvas.js"></script>
    <script src="__STATIC__/js/jquery.qrcode.min.js"></script>
    <script>
        function closezalert(){
            $('.alertdiv').hide();
        }
        $('#qrcode').qrcode({width: 110,height: 110,text: "{:cmf_get_domain()}{:url('user/register/index',array('recommender_code'=>$user_relation.invitation_code))}"});

        var savaFile=function(data,filename)
        {
            var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
            save_link.href = data;
            save_link.download = filename;
            var event=document.createEvent('MouseEvents');
            event.initMouseEvent('click',true,false,window,0,0,0,0,0,false,false,false,false,0,null);
            save_link.dispatchEvent(event);
        };
        
        function sctp(){
            new html2canvas(document.getElementById('haibaobg'),{useCORS: true }).then(canvas => {
                // canvas为转换后的Canvas对象
                let oImg = new Image();
                oImg.src = canvas.toDataURL("image/png");  // 导出图片
                //document.body.appendChild(oImg);  // 将生成的图片添加到body
                console.log(oImg)
                let time1 = new Date().getTime()
                savaFile(oImg.src,time1)
            });
        }
        
        function CopyCode(obj) {
            let url = $('#haibaoa')[0];
            console.log(url)
            url.select();
            document.execCommand("Copy");
            $('.alertdiv').show();
        }

        function CopyUrl(obj) {
            let url = $('#url')[0];
            console.log(url)
            url.select();
            document.execCommand("Copy");
            $('.alertdiv').show();
        }
    </script>
</body>
</html>